package cn.cqone.crm.controller;

import cn.cqone.crm.domain.Employee;
import cn.cqone.crm.domain.Menu;
import cn.cqone.crm.query.MenuQuery;
import cn.cqone.crm.service.MenuService;
import cn.cqone.crm.utils.JSONResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/menu")
@CrossOrigin
@RequiresPermissions("menu:main")
public class MenuController extends BaseController<Menu,Long,MenuQuery>{

    @Autowired
    private MenuService menuService;

    //查询全部数据
    @RequestMapping(value = "/findMenu",method = RequestMethod.GET)
    public JSONResult findAll(){
        try{
            List<Menu> list = menuService.findMenu();
            return JSONResult.ok(list);
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.error("服务器异常,我们正在殴打程序员...");
        }
    }

    //根据id查询数据
    @RequestMapping(value = "/findMenuByEmployeeId",method = RequestMethod.POST)
    public JSONResult findMenuByEmployeeId(@RequestBody Employee employee){
        try{
            List<Menu> list = menuService.findMenuByEmployeeId(employee.getId());
            return JSONResult.ok(list);
        }catch (Exception e){
            e.printStackTrace();
            return JSONResult.error("服务器异常,我们正在殴打程序员...");
        }
    }
}
